package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.example.demo.entity.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
@RestController //@Controller+@ResponseBody
public class MovieController {
	@Autowired
	private RestTemplate restTemplate;
	
	
	
	@GetMapping("/movie/{id}") //@RequestMapping(method={GET})
	@HystrixCommand(fallbackMethod = "defaultStores") //设置只想fallback的方法
	public User getMovieUser(@PathVariable Long id) {
		// VIP： virtual IP 
		return restTemplate.getForObject("http://microservice-provider-user/getUser/" + id, User.class);
	}
	
	
	public User defaultStores(Long id) {
		// VIP： virtual IP 
		User user = new User();
		user.setId(0L);
		return user;
	}
	
}
